package chapter19.homework3;

import java.util.ArrayList;

public class HomepageIterator implements AbstractIterator{
    private ArrayList<Object> homepages;//
    private int cursor1;//得到游标..
    private int cursor2;

    public HomepageIterator(HomepageList homepageList){
        this.homepages = homepageList.arrayList;//获取集合对象..
        cursor1 = 0;//获得正向的初始化值
        cursor2 = homepages.size();//获得逆向的初始值
    }

    @Override
    public void next() {//下一页
        if (cursor1 < homepages.size()){
            cursor1++;
        }
    }

    @Override
    public void previous() {//返回上一页
        if (cursor2 > -1){
            cursor2--;
        }
    }

    @Override
    public Object getNextIem() {//获取元素
        return homepages.get(cursor1);
    }

    @Override
    public Object getPreviousItem() {
        return homepages.get(cursor2);//获取元素
    }

    @Override
    public boolean isLast() {
        return (cursor1 == homepages.size());//是否为第一个元素
    }

    @Override
    public boolean isFirst() {
        return (cursor2 == homepages.size());
    }
}
